import http from './http'
import moment from "dayjs"
export function getEquipmentOperationRecords2(params) {

  return http.get(`/Upload/record_${params.equipmentId}.json`, {
    params
  }).then(res => {
    let prev;
    if (params.equipmentId != 14) {
      let list = res.list || [];
      let day = (params.page || 1) - 1;
      let now = +new Date();
      list = list.map((i, index) => {
        let r = (Math.random() * 20) + 2;
        if (prev) {
          prev += r;
        } else {
          prev = r;
        }

        let d = Math.round(prev);
        let nowM = moment(now);
        let time = nowM.subtract(day, 'days').subtract(d, "minute").format("YYYY-MM-DD HH:mm:ss")
        return {
          ...i,
          id: i.id + "" + index + day,
          time
        }
      })
      res.list = list;
      return res;
    } else {
      if (params.page == 1 || !params.page) {
        return res

      } else {
        return {
          list: [],
          total: 0
        }
      }
    }

  }).catch(err => ({
    list: [],
    total: 0
  }))
}